<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Notepad</title>

    <!-- bootstrap -->
    <link rel="stylesheet" href="./assets/css/bootstrap.min.css" />

    <!-- animate.css -->
    <link rel="stylesheet" href="./assets/css/animate.min.css" />

    <!-- 重置样式 -->
    <link rel="stylesheet" href="./assets/css/reset.css" />

    <!-- mui框架css -->
    <link rel="stylesheet" href="./assets/plugins/mui/css/mui.min.css">

    <!-- 表单校验插件 -->
    <link rel="stylesheet" href="./assets/plugins/BootstrapValidator/bootstrapValidator.min.css">

    <!-- 公共样式 -->
    <link rel="stylesheet" href="./assets/css/common.css" />

    <!-- 页面独立的 -->
    <link rel="stylesheet" href="./assets/css/UserLogin.css" />
</head>

<body>
    <!-- 用户信息 -->
    <div class="user">
        <div class="avatar wow fadeInUp">
            <img src="./assets/images/avatar.png" />
        </div>

        <div class="notice wow fadeInUp" data-wow-delay="100ms">登录</div>
    </div>

    <form class="login wow fadeInUp" data-wow-delay="200ms" method="post" action="api/register.php">
        <div class="form-group">
            <label for="phone">电话号码</label>
            <input type="text" class="form-control" id="mobile" name="mobile" placeholder="请输入手机号" />
        </div>

        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" />
        </div>

        <div class="action">
            <button class="btn" type="submit">登 录</button>
        </div>
 
        <div class="action" style="text-align: center;">
            <a href="register.html">注册页面</a>
        </div>
    </form>
</body>

</html>
<!-- jquery  -->
<script src="./assets/js/jquery.min.js"></script>

<!-- bootstrap -->
<script src="./assets/js/bootstrap.min.js"></script>

<!-- wow.js -->
<script src="./assets/js/wow.min.js"></script>

<!-- mui框架js -->
<script src="./assets/plugins/mui/js/mui.min.js"></script>

<!-- 表单校验插件 -->
<script src="./assets/plugins/BootstrapValidator/bootstrapValidator.min.js"></script>

<!-- 请求插件 -->
<script src="./assets/plugins/axios/axios.min.js"></script>
<script src="./assets/plugins/axios/request.js"></script>

<!-- 引入cookie插件 -->
<script src="./assets/plugins/cookle.js"></script>

<script>
    //实例化wow.js
    new WOW().init()

    // 表单校验
    $('form').bootstrapValidator({
        // 默认提示图标
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            mobile: { // 字段名
                validators: {
                    notEmpty: { // 非空校验
                        message: '电话号码不能为空!'
                    },
                    // 手机号码的正则校验
                    regexp: { //正则校验
                        regexp: /^1[356789]\d{9}$/,
                        message: '电话号码格式错误'
                    },
                },
            },
            password: {
                validators: {
                    notEmpty: {
                        message: '密码不能为空'
                    },
                    stringLength: {
                        min: 4,
                        max: 12,
                        message: '密码长度必须在4-12位之间'
                    }
                }
            }
        }
    }).on('success.form.bv', function (e) {
        //阻止多次提交事件
        e.preventDefault()
    })

    // 表单提交事件
    $('form').submit(async function () {
        // 阻止表单提交默认事件
        // e.preventDefault();
        // console.log(111);
        // mui.toast('登陆成功')
        // 发送 POST 请求
        let result = await POST({
            url: 'business/login', params: {
                mobile: $('#mobile').val(),
                password: $('#password').val()
            }
        })
        if (result.code == 1) {
            mui.toast(result.msg);
            // 存储用户信息
            cookie.set('Business', JSON.stringify(result.data))
            setTimeout(() => {
                location.href = 'my.html'
            }, 500)
        }
        else {
            mui.toast(result.msg);
        }
    })
</script>